<template>
  <div id="app">
    <div class="route-menu">
      {{ num }}
      <el-button @click="changeData">修改数据</el-button>
      <router-link to="/pageA?id=1">A</router-link>
      <el-button @click="goPage('/path')">跳转到B页面</el-button>
      <el-button @click="goPage('/vuex-demo')">VuexDemo{{ $store.getters.countResult }}</el-button>
    </div>
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
  </div>
</template>

<script>

export default {
  name: 'App',
  components: {
    
  },
  data() {
    return {
      arr:[],
      num: 0,
      name: '斌',
      obj: {
        key: 'value',
        name: '斌'
      }
    }
  },
  created() {
    this.func()
  },
  methods: {
    changeData() {
      this.num++
    },
    goPage(path) {
      console.log(111)
      this.$router.push({path})
    },
    doClck() {

    },
    func() {
      let obj = {
        key: 'value',
        name: '斌'
      }
      this.doBind(obj, 'name', obj['name'])

      console.log(obj.name)
      obj.name = '234'

    },
    doBind(obj,key,value) {
      Object.defineProperty(obj, key, {
        // set & get 典型的闭包，在父级函数外 获取/设置 对象属性时会调用get/get方法，return/修改 的是父级函数作用域下的value
        //取值
        get() {
          console.log('执行了get方法读取', key, '成功')
          return value
        },
        //设置值
        set(newValue) {
          if (value === newValue) return
          console.log('监听赋值成功', newValue)
          value = newValue
        }
      })
    }
  }
}
</script>

<style lang="scss">
.route-menu{
  display: flex;
  justify-content: space-around;
}
</style>
